#include "addgdbdialog.h"
#include "ui_addgdbdialog.h"

AddGDBDialog::AddGDBDialog(QStringList GDBListIn,QWidget *parent) :
    QDialog(parent),GDBList(GDBListIn),
    ui(new Ui::AddGDBDialog)
{
    ui->setupUi(this);

    iniMainDialog();

    connect(this,&AddGDBDialog::sigAddGDBData,
            AppEvent::getInstance(),&AppEvent::on_AddGDBData);
    connect(btnOK,&QPushButton::clicked,
            this,&AddGDBDialog::on_btnOK_clicked);
    connect(btnCancel,&QPushButton::clicked,
            this,&AddGDBDialog::on_btnCancel_clicked);
}

AddGDBDialog::~AddGDBDialog()
{
    delete ui;
}

void AddGDBDialog::iniMainDialog()
{
    QFormLayout *formLayout=new QFormLayout();
    comboxGDBList=new QComboBox();
    comboxGDBList->addItems(GDBList);
    formLayout->insertRow(0,QObject::tr("Database Name:"),comboxGDBList);
    btnOK=new QPushButton();
    btnOK->setText(QObject::tr("OK"));
    btnCancel=new QPushButton();
    btnCancel->setText(QObject::tr("Cancel"));
    QHBoxLayout *btnLayout=new QHBoxLayout();
    btnLayout->addWidget(btnOK);
    btnLayout->addWidget(btnCancel);
    QVBoxLayout *mainLayout=new QVBoxLayout();
    mainLayout->addLayout(formLayout);
    mainLayout->addLayout(btnLayout);
    this->setLayout(mainLayout);
}

void AddGDBDialog::on_btnOK_clicked()
{
    QString GDBName=comboxGDBList->currentText();
    //int fieldIndex=comboxGDBList->currentIndex();
    //emit sigDeleteField(fieldIndex);
    emit sigAddGDBData(GDBName);
    this->close();
}

void AddGDBDialog::on_btnCancel_clicked()
{
    this->close();
}
